﻿using RuoVea.ExCrypt.Extensions;
using System;
using System.Security.Cryptography;
using System.Text;

namespace RuoVea.ExCrypt
{
    /// <summary>
    /// SHA256
    /// </summary>
    public class SHA256Crypt
    {
        #region SHA256
        /// <summary>
        /// SHA256 encrypt
        /// </summary>
        /// <param name="srcString">The string to be encrypted</param>
        /// <returns></returns>
        public static string Encrypt(string srcString)
        {
            Check.Argument.IsNotEmpty(srcString, nameof(srcString));

            using (SHA256 sha256 = SHA256.Create())
            {
                byte[] bytes_sha256_in = Encoding.UTF8.GetBytes(srcString);
                byte[] bytes_sha256_out = sha256.ComputeHash(bytes_sha256_in);
                string str_sha256_out = BitConverter.ToString(bytes_sha256_out);
                str_sha256_out = str_sha256_out.Replace("-", "");
                return str_sha256_out;
            }
        }
        #endregion
    }
}
